/**
 * 
 */
package service.impl;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import dao.CommentDAO;
import dao.DiaryDAO;
import dao.impl.CommentDAOImpl;
import dao.impl.DiaryDAOImpl;
import po.Diary;
import service.DiaryService;
import util.DBUtil;

/**
 * @author 曹桢瑞
 *
 */
public class DiaryServiceImpl implements DiaryService {

	@Override
	public ArrayList<Diary> getDiaryInfo(String userId, long submitTime) {
		Connection con=null;
		ArrayList<Diary> list=new ArrayList<Diary>();
		try {
			con=DBUtil.getConnection();
			DiaryDAO diaryDAO=new DiaryDAOImpl(con);
			list=diaryDAO.getDiary(userId, submitTime);
		}
		catch(Exception e) {
			System.out.println(e);
		}
		return list;
	}

	@Override
	public List<Diary> getDiaryInfoByUserId(String userId, int num) {
		Connection con=null;
		ArrayList<Diary> list=new ArrayList<Diary>();
		try {
			con=DBUtil.getConnection();
			DiaryDAO diaryDAO=new DiaryDAOImpl(con);
			list=diaryDAO.getDiaryList(userId, num);
		}
		catch(Exception e) {
			System.out.println(e);
		}
		return list;
	}

	@Override
	public boolean addDiary(Diary diary) {
		Connection con=null;
		boolean flag=false;
		try {
			con=DBUtil.getConnection();
			DiaryDAO diaryDAO=new DiaryDAOImpl(con);
			flag=diaryDAO.addDiary(diary);
		}
		catch(Exception e) {
			System.out.println(e);
		}
		return flag;
	}

	@Override
	public boolean removeDiary(Diary diary) {
		Connection con=null;
		boolean flag=false;
		try {
			con=DBUtil.getConnection();
			DiaryDAO diaryDAO=new DiaryDAOImpl(con);
			flag=diaryDAO.removeDiary(diary.getUserId(), diary.getSubmitTime());
		}
		catch(Exception e) {
			System.out.println(e);
		}
		return flag;
	}

	@Override
	public boolean updateDiary(Diary diary) {
		Connection con=null;
		boolean flag=false;
		try {
			con=DBUtil.getConnection();
			DiaryDAO diaryDAO=new DiaryDAOImpl(con);
			flag=diaryDAO.updateDiary(diary);
		}
		catch(Exception e) {
			System.out.println(e);
		}
		return flag;
	}

}
